package cn.gwm.utils;

import cn.gwm.flink.streaming.beans.GwmDataObj;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * 定义json解析的工具类
 * 业务中多次会使用到json反序列化为javaBean的操作，因此可以提前定义好转换方法，每个业务主题开发的时候只需要调用即可，大大提高代码的开发效率
 * <p>
 * 1）接受传入的json字符串，然后将json字符串反序列化成javaBean返回
 */
public class JsonParseUtil {
    //todo 1）定义日志打印对象
    private static Logger logger = LoggerFactory.getLogger(JsonParseUtil.class);

    //todo 2）接受传入的json字符串，然后将json字符串反序列化成javaBean返回
    public static GwmDataObj parserJsonToBean(String jsonStr) {
        //定义需要返回的GwmDataObj对象
        GwmDataObj GwmDataObj = new GwmDataObj();

        try {
            //将字符串转换成HashMap对象
            final HashMap<String, Object> vehicleMap = jsonToHashMap(jsonStr);
            //档位驱动力状态	0：无驱动力 1：有驱动力
            GwmDataObj.setGearDriveForce(convertIntType("gearDriveForce", vehicleMap));
            GwmDataObj.setBatteryConsistencyDifferenceAlarm(convertIntType("batteryConsistencyDifferenceAlarm", vehicleMap));
            GwmDataObj.setSoc(convertIntType("soc", vehicleMap));
            GwmDataObj.setSocJumpAlarm(convertIntType("socJumpAlarm", vehicleMap));
            GwmDataObj.setCaterpillaringFunction(convertIntType("caterpillaringFunction", vehicleMap));
            GwmDataObj.setSatNum(convertIntType("satNum", vehicleMap));
            GwmDataObj.setSocLowAlarm(convertIntType("socLowAlarm", vehicleMap));
            GwmDataObj.setChargingGunConnectionState(convertIntType("chargingGunConnectionState", vehicleMap));
            GwmDataObj.setMinTemperatureSubSystemNum(convertIntType("minTemperatureSubSystemNum", vehicleMap));
            GwmDataObj.setChargedElectronicLockStatus(convertIntType("chargedElectronicLockStatus", vehicleMap));
            GwmDataObj.setMaxVoltageBatteryNum(convertIntType("maxVoltageBatteryNum", vehicleMap));
            GwmDataObj.setTerminalTime(convertStringType("terminalTime", vehicleMap));
            GwmDataObj.setSingleBatteryOverVoltageAlarm(convertIntType("singleBatteryOverVoltageAlarm", vehicleMap));
            GwmDataObj.setOtherFaultCount(convertIntType("otherFaultCount", vehicleMap));
            GwmDataObj.setVehicleStorageDeviceOvervoltageAlarm(convertIntType("vehicleStorageDeviceOvervoltageAlarm", vehicleMap));
            GwmDataObj.setBrakeSystemAlarm(convertIntType("brakeSystemAlarm", vehicleMap));
            GwmDataObj.setServerTime(convertStringType("serverTime", vehicleMap));
            GwmDataObj.setVin(convertStringType("vin", vehicleMap).toUpperCase());
            GwmDataObj.setRechargeableStorageDevicesFaultCount(convertIntType("rechargeableStorageDevicesFaultCount", vehicleMap));
            GwmDataObj.setDriveMotorTemperatureAlarm(convertIntType("driveMotorTemperatureAlarm", vehicleMap));
            GwmDataObj.setGearBrakeForce(convertIntType("gearBrakeForce", vehicleMap));
            GwmDataObj.setDcdcStatusAlarm(convertIntType("dcdcStatusAlarm", vehicleMap));
            GwmDataObj.setLat(convertDoubleType("lat", vehicleMap));
            GwmDataObj.setDriveMotorFaultCodes(convertStringType("driveMotorFaultCodes", vehicleMap));
            GwmDataObj.setDeviceType(convertStringType("deviceType", vehicleMap));
            GwmDataObj.setVehicleSpeed(convertDoubleType("vehicleSpeed", vehicleMap));
            GwmDataObj.setLng(convertDoubleType("lng", vehicleMap));
            GwmDataObj.setChargingTimeExtensionReason(convertIntType("chargingTimeExtensionReason", vehicleMap));
            GwmDataObj.setGpsTime(convertStringType("gpsTime", vehicleMap));
            GwmDataObj.setEngineFaultCount(convertIntType("engineFaultCount", vehicleMap));
            GwmDataObj.setCarId(convertStringType("carId", vehicleMap));
            GwmDataObj.setCurrentElectricity(convertDoubleType("vehicleSpeed", vehicleMap));
            GwmDataObj.setSingleBatteryUnderVoltageAlarm(convertIntType("singleBatteryUnderVoltageAlarm", vehicleMap));
            GwmDataObj.setMaxVoltageBatterySubSystemNum(convertIntType("maxVoltageBatterySubSystemNum", vehicleMap));
            GwmDataObj.setMinTemperatureProbe(convertIntType("minTemperatureProbe", vehicleMap));
            GwmDataObj.setDriveMotorNum(convertIntType("driveMotorNum", vehicleMap));
            GwmDataObj.setTotalVoltage(convertDoubleType("totalVoltage", vehicleMap));
            GwmDataObj.setTemperatureDifferenceAlarm(convertIntType("temperatureDifferenceAlarm", vehicleMap));
            GwmDataObj.setMaxAlarmLevel(convertIntType("maxAlarmLevel", vehicleMap));
            GwmDataObj.setStatus(convertIntType("status", vehicleMap));
            GwmDataObj.setGeerPosition(convertIntType("geerPosition", vehicleMap));
            GwmDataObj.setAverageEnergyConsumption(convertDoubleType("averageEnergyConsumption", vehicleMap));
            GwmDataObj.setMinVoltageBattery(convertDoubleType("minVoltageBattery", vehicleMap));
            GwmDataObj.setGeerStatus(convertIntType("geerStatus", vehicleMap));
            GwmDataObj.setMinVoltageBatteryNum(convertIntType("minVoltageBatteryNum", vehicleMap));
            GwmDataObj.setValidGps(convertStringType("validGps", vehicleMap));
            GwmDataObj.setEngineFaultCodes(convertStringType("engineFaultCodes", vehicleMap));
            GwmDataObj.setMinTemperatureValue(convertDoubleType("minTemperatureValue", vehicleMap));
            GwmDataObj.setChargeStatus(convertIntType("chargeStatus", vehicleMap));
            GwmDataObj.setIgnitionTime(convertStringType("ignitionTime", vehicleMap));
            GwmDataObj.setTotalOdometer(convertDoubleType("totalOdometer", vehicleMap));
            GwmDataObj.setAlti(convertDoubleType("alti", vehicleMap));
            GwmDataObj.setSpeed(convertDoubleType("speed", vehicleMap));
            GwmDataObj.setSocHighAlarm(convertIntType("socHighAlarm", vehicleMap));
            GwmDataObj.setVehicleStorageDeviceUndervoltageAlarm(convertIntType("vehicleStorageDeviceUndervoltageAlarm", vehicleMap));
            GwmDataObj.setTotalCurrent(convertDoubleType("totalCurrent", vehicleMap));
            GwmDataObj.setBatteryAlarm(convertIntType("batteryAlarm", vehicleMap));
            GwmDataObj.setRechargeableStorageDeviceMismatchAlarm(convertIntType("rechargeableStorageDeviceMismatchAlarm", vehicleMap));
            GwmDataObj.setIsHistoryPoi(convertIntType("isHistoryPoi", vehicleMap));
            GwmDataObj.setVehiclePureDeviceTypeOvercharge(convertIntType("vehiclePureDeviceTypeOvercharge", vehicleMap));
            GwmDataObj.setMaxVoltageBattery(convertDoubleType("maxVoltageBattery", vehicleMap));
            GwmDataObj.setDcdcTemperatureAlarm(convertIntType("dcdcTemperatureAlarm", vehicleMap));
            GwmDataObj.setIsValidGps(convertStringType("isValidGps", vehicleMap));
            GwmDataObj.setLastUpdatedTime(convertStringType("lastUpdatedTime", vehicleMap));
            GwmDataObj.setDriveMotorControllerTemperatureAlarm(convertIntType("driveMotorControllerTemperatureAlarm", vehicleMap));
            GwmDataObj.setIgniteCumulativeMileage(convertDoubleType("igniteCumulativeMileage", vehicleMap));
            GwmDataObj.setDcStatus(convertIntType("dcStatus", vehicleMap));
            GwmDataObj.setRepay(convertStringType("repay", vehicleMap));
            GwmDataObj.setMaxTemperatureSubSystemNum(convertIntType("maxTemperatureSubSystemNum", vehicleMap));
            GwmDataObj.setMinVoltageBatterySubSystemNum(convertIntType("minVoltageBatterySubSystemNum", vehicleMap));
            GwmDataObj.setHeading(convertDoubleType("heading", vehicleMap));
            GwmDataObj.setTuid(convertStringType("tuid", vehicleMap));
            GwmDataObj.setEnergyRecoveryStatus(convertIntType("energyRecoveryStatus", vehicleMap));
            GwmDataObj.setFireStatus(convertIntType("fireStatus", vehicleMap));
            GwmDataObj.setTargetType(convertStringType("targetType", vehicleMap));
            GwmDataObj.setMaxTemperatureProbe(convertIntType("maxTemperatureProbe", vehicleMap));
            GwmDataObj.setRechargeableStorageDevicesFaultCodes(convertStringType("rechargeableStorageDevicesFaultCodes", vehicleMap));
            GwmDataObj.setCarMode(convertIntType("carMode", vehicleMap));
            GwmDataObj.setHighVoltageInterlockStateAlarm(convertIntType("highVoltageInterlockStateAlarm", vehicleMap));
            GwmDataObj.setInsulationAlarm(convertIntType("insulationAlarm", vehicleMap));
            GwmDataObj.setMileageInformation(convertIntType("mileageInformation", vehicleMap));
            GwmDataObj.setMaxTemperatureValue(convertDoubleType("maxTemperatureValue", vehicleMap));
            GwmDataObj.setOtherFaultCodes(convertStringType("otherFaultCodes", vehicleMap));
            GwmDataObj.setRemainPower(convertDoubleType("remainPower", vehicleMap));
            GwmDataObj.setInsulateResistance(convertIntType("insulateResistance", vehicleMap));
            GwmDataObj.setBatteryLowTemperatureHeater(convertIntType("batteryLowTemperatureHeater", vehicleMap));
            GwmDataObj.setFuelConsumption100km(convertStringType("fuelConsumption100km", vehicleMap));
            GwmDataObj.setFuelConsumption(convertStringType("fuelConsumption", vehicleMap));
            GwmDataObj.setEngineSpeed(convertStringType("engineSpeed", vehicleMap));
            GwmDataObj.setEngineStatus(convertStringType("engineStatus", vehicleMap));
            GwmDataObj.setTrunk(convertIntType("trunk", vehicleMap));
            GwmDataObj.setLowBeam(convertIntType("lowBeam", vehicleMap));
            GwmDataObj.setTriggerLatchOverheatProtect(convertStringType("triggerLatchOverheatProtect", vehicleMap));
            GwmDataObj.setTurnLndicatorRight(convertIntType("turnLndicatorRight", vehicleMap));
            GwmDataObj.setHighBeam(convertIntType("highBeam", vehicleMap));
            GwmDataObj.setTurnLndicatorLeft(convertIntType("turnLndicatorLeft", vehicleMap));
            GwmDataObj.setBcuSwVers(convertIntType("bcuSwVers", vehicleMap));
            GwmDataObj.setBcuHwVers(convertIntType("bcuHwVers", vehicleMap));
            GwmDataObj.setBcuOperMod(convertIntType("bcuOperMod", vehicleMap));
            GwmDataObj.setChrgEndReason(convertIntType("chrgEndReason", vehicleMap));
            GwmDataObj.setBCURegenEngDisp(convertStringType("BCURegenEngDisp", vehicleMap));
            GwmDataObj.setBCURegenCpDisp(convertIntType("BCURegenCpDisp", vehicleMap));
            GwmDataObj.setBcuChrgMod(convertIntType("bcuChrgMod", vehicleMap));
            GwmDataObj.setBatteryChargeStatus(convertIntType("batteryChargeStatus", vehicleMap));
            GwmDataObj.setBcuFltRnk(convertIntType("bcuFltRnk", vehicleMap));
            GwmDataObj.setBattPoleTOver(convertStringType("battPoleTOver", vehicleMap));
            GwmDataObj.setBcuSOH(convertDoubleType("bcuSOH", vehicleMap));
            GwmDataObj.setBattIntrHeatActive(convertIntType("battIntrHeatActive", vehicleMap));
            GwmDataObj.setBattIntrHeatReq(convertIntType("battIntrHeatReq", vehicleMap));
            GwmDataObj.setBCUBattTarT(convertStringType("BCUBattTarT", vehicleMap));
            GwmDataObj.setBattExtHeatReq(convertIntType("battExtHeatReq", vehicleMap));
            GwmDataObj.setBCUMaxChrgPwrLongT(convertStringType("BCUMaxChrgPwrLongT", vehicleMap));
            GwmDataObj.setBCUMaxDchaPwrLongT(convertStringType("BCUMaxDchaPwrLongT", vehicleMap));
            GwmDataObj.setBCUTotalRegenEngDisp(convertStringType("BCUTotalRegenEngDisp", vehicleMap));
            GwmDataObj.setBCUTotalRegenCpDisp(convertStringType("BCUTotalRegenCpDisp ", vehicleMap));
            GwmDataObj.setDcdcFltRnk(convertIntType("dcdcFltRnk", vehicleMap));
            GwmDataObj.setDcdcOutpCrrt(convertDoubleType("dcdcOutpCrrt", vehicleMap));
            GwmDataObj.setDcdcOutpU(convertDoubleType("dcdcOutpU", vehicleMap));
            GwmDataObj.setDcdcAvlOutpPwr(convertIntType("dcdcAvlOutpPwr", vehicleMap));
            GwmDataObj.setAbsActiveStatus(convertStringType("absActiveStatus", vehicleMap));
            GwmDataObj.setAbsStatus(convertStringType("absStatus", vehicleMap));
            GwmDataObj.setVcuBrkErr(convertStringType("VcuBrkErr", vehicleMap));
            GwmDataObj.setEPB_AchievedClampForce(convertStringType("EPB_AchievedClampForce", vehicleMap));
            GwmDataObj.setEpbSwitchPosition(convertStringType("epbSwitchPosition", vehicleMap));
            GwmDataObj.setEpbStatus(convertStringType("epbStatus", vehicleMap));
            GwmDataObj.setEspActiveStatus(convertStringType("espActiveStatus", vehicleMap));
            GwmDataObj.setEspFunctionStatus(convertStringType("espFunctionStatus", vehicleMap));
            GwmDataObj.setESP_TCSFailStatus(convertStringType("ESP_TCSFailStatus", vehicleMap));
            GwmDataObj.setHhcActive(convertStringType("hhcActive", vehicleMap));
            GwmDataObj.setTcsActive(convertStringType("tcsActive", vehicleMap));
            GwmDataObj.setEspMasterCylinderBrakePressure(convertStringType("espMasterCylinderBrakePressure", vehicleMap));
            GwmDataObj.setESP_MasterCylinderBrakePressureValid(convertStringType("ESP_MasterCylinderBrakePressureValid", vehicleMap));
            GwmDataObj.setEspTorqSensorStatus(convertStringType("espTorqSensorStatus", vehicleMap));
            GwmDataObj.setEPS_EPSFailed(convertStringType("EPS_EPSFailed", vehicleMap));
            GwmDataObj.setSasFailure(convertStringType("sasFailure", vehicleMap));
            GwmDataObj.setSasSteeringAngleSpeed(convertStringType("sasSteeringAngleSpeed", vehicleMap));
            GwmDataObj.setSasSteeringAngle(convertStringType("sasSteeringAngle", vehicleMap));
            GwmDataObj.setSasSteeringAngleValid(convertStringType("sasSteeringAngleValid", vehicleMap));
            GwmDataObj.setEspSteeringTorque(convertStringType("espSteeringTorque", vehicleMap));
            GwmDataObj.setAcReq(convertIntType("acReq", vehicleMap));
            GwmDataObj.setAcSystemFailure(convertIntType("acSystemFailure", vehicleMap));
            GwmDataObj.setPtcPwrAct(convertDoubleType("ptcPwrAct", vehicleMap));
            GwmDataObj.setPlasmaStatus(convertIntType("plasmaStatus", vehicleMap));
            GwmDataObj.setBattInTemperature(convertIntType("battInTemperature", vehicleMap));
            GwmDataObj.setBattWarmLoopSts(convertStringType("battWarmLoopSts", vehicleMap));
            GwmDataObj.setBattCoolngLoopSts(convertStringType("battCoolngLoopSts", vehicleMap));
            GwmDataObj.setBattCoolActv(convertStringType("battCoolActv", vehicleMap));
            GwmDataObj.setMotorOutTemperature(convertIntType("motorOutTemperature", vehicleMap));
            GwmDataObj.setPowerStatusFeedBack(convertStringType("powerStatusFeedBack", vehicleMap));
            GwmDataObj.setAC_RearDefrosterSwitch(convertIntType("AC_RearDefrosterSwitch", vehicleMap));
            GwmDataObj.setRearFoglamp(convertIntType("rearFoglamp", vehicleMap));
            GwmDataObj.setDriverDoorLock(convertIntType("driverDoorLock", vehicleMap));
            GwmDataObj.setAcDriverReqTemp(convertDoubleType("acDriverReqTemp", vehicleMap));
            GwmDataObj.setKeyAlarm(convertIntType("keyAlarm", vehicleMap));
            GwmDataObj.setAirCleanStsRemind(convertIntType("airCleanStsRemind", vehicleMap));
            GwmDataObj.setRecycleType(convertIntType("recycleType", vehicleMap));
            GwmDataObj.setStartControlsignal(convertStringType("startControlsignal", vehicleMap));
            GwmDataObj.setAirBagWarningLamp(convertIntType("airBagWarningLamp", vehicleMap));
            GwmDataObj.setFrontDefrosterSwitch(convertIntType("frontDefrosterSwitch", vehicleMap));
            GwmDataObj.setFrontBlowType(convertStringType("frontBlowType", vehicleMap));
            GwmDataObj.setFrontReqWindLevel(convertIntType("frontReqWindLevel", vehicleMap));
            GwmDataObj.setBcmFrontWiperStatus(convertStringType("bcmFrontWiperStatus", vehicleMap));
            GwmDataObj.setTmsPwrAct(convertStringType("tmsPwrAct", vehicleMap));
            GwmDataObj.setKeyUndetectedAlarmSign(convertIntType("keyUndetectedAlarmSign", vehicleMap));
            GwmDataObj.setPositionLamp(convertStringType("positionLamp", vehicleMap));
            GwmDataObj.setDriverReqTempModel(convertIntType("driverReqTempModel", vehicleMap));
            GwmDataObj.setTurnLightSwitchSts(convertIntType("turnLightSwitchSts", vehicleMap));
            GwmDataObj.setAutoHeadlightStatus(convertIntType("autoHeadlightStatus", vehicleMap));
            GwmDataObj.setDriverDoor(convertIntType("driverDoor", vehicleMap));
            GwmDataObj.setFrntIpuFltRnk(convertIntType("frntIpuFltRnk", vehicleMap));
            GwmDataObj.setFrontIpuSwVers(convertStringType("frontIpuSwVers", vehicleMap));
            GwmDataObj.setFrontIpuHwVers(convertIntType("frontIpuHwVers", vehicleMap));
            GwmDataObj.setFrntMotTqLongTermMax(convertIntType("frntMotTqLongTermMax", vehicleMap));
            GwmDataObj.setFrntMotTqLongTermMin(convertIntType("frntMotTqLongTermMin", vehicleMap));
            GwmDataObj.setCpvValue(convertIntType("cpvValue", vehicleMap));
            GwmDataObj.setObcChrgSts(convertIntType("obcChrgSts", vehicleMap));
            GwmDataObj.setObcFltRnk(convertStringType("obcFltRnk", vehicleMap));
            GwmDataObj.setObcChrgInpAcI(convertDoubleType("obcChrgInpAcI", vehicleMap));
            GwmDataObj.setObcChrgInpAcU(convertIntType("obcChrgInpAcU", vehicleMap));
            GwmDataObj.setObcChrgDcI(convertDoubleType("obcChrgDcI", vehicleMap));
            GwmDataObj.setObcChrgDcU(convertDoubleType("obcChrgDcU", vehicleMap));
            GwmDataObj.setObcTemperature(convertIntType("obcTemperature", vehicleMap));
            GwmDataObj.setObcMaxChrgOutpPwrAvl(convertIntType("obcMaxChrgOutpPwrAvl", vehicleMap));
            GwmDataObj.setPassengerBuckleSwitch(convertIntType("passengerBuckleSwitch", vehicleMap));
            GwmDataObj.setCrashlfo(convertStringType("crashlfo", vehicleMap));
            GwmDataObj.setDriverBuckleSwitch(convertIntType("driverBuckleSwitch", vehicleMap));
            GwmDataObj.setEngineStartHibit(convertStringType("engineStartHibit", vehicleMap));
            GwmDataObj.setLockCommand(convertStringType("lockCommand", vehicleMap));
            GwmDataObj.setSearchCarReq(convertStringType("searchCarReq", vehicleMap));
            GwmDataObj.setAcTempValueReq(convertStringType("acTempValueReq", vehicleMap));
            GwmDataObj.setVcuErrAmnt(convertStringType("vcuErrAmnt", vehicleMap));
            GwmDataObj.setVcuSwVers(convertIntType("vcuSwVers", vehicleMap));
            GwmDataObj.setVcuHwVers(convertIntType("vcuHwVers", vehicleMap));
            GwmDataObj.setLowSpdWarnStatus(convertStringType("lowSpdWarnStatus", vehicleMap));
            GwmDataObj.setLowBattChrgRqe(convertIntType("lowBattChrgRqe", vehicleMap));
            GwmDataObj.setLowBattChrgSts(convertStringType("lowBattChrgSts", vehicleMap));
            GwmDataObj.setLowBattU(convertDoubleType("lowBattU", vehicleMap));
            GwmDataObj.setHandlebrakeStatus(convertIntType("handlebrakeStatus", vehicleMap));
            GwmDataObj.setShiftPositionValid(convertStringType("shiftPositionValid", vehicleMap));
            GwmDataObj.setAccPedalValid(convertStringType("accPedalValid", vehicleMap));
            GwmDataObj.setDriveMode(convertIntType("driveMode", vehicleMap));
            GwmDataObj.setDriveModeButtonStatus(convertIntType("driveModeButtonStatus", vehicleMap));
            GwmDataObj.setVCUSRSCrashOutpSts(convertIntType("VCUSRSCrashOutpSts", vehicleMap));
            GwmDataObj.setTextDispEna(convertIntType("textDispEna", vehicleMap));
            GwmDataObj.setCrsCtrlStatus(convertIntType("crsCtrlStatus", vehicleMap));
            GwmDataObj.setCrsTarSpd(convertIntType("crsTarSpd", vehicleMap));
            GwmDataObj.setCrsTextDisp(convertIntType("crsTextDisp", vehicleMap));
            GwmDataObj.setKeyOn(convertIntType("keyOn", vehicleMap));
            GwmDataObj.setVehPwrlim(convertIntType("vehPwrlim", vehicleMap));
            GwmDataObj.setVehCfgInfo(convertStringType("vehCfgInfo", vehicleMap));
            GwmDataObj.setVacBrkPRmu(convertIntType("vacBrkPRmu", vehicleMap));

            //================新能源汽车可充电储能子系统电压信息列表(nevChargeSystemVoltageDtoList)===========
            final List<HashMap<String, Object>> nevChargeSystemVoltageDtoList = jsonToList(
                    vehicleMap.getOrDefault("nevChargeSystemVoltageDtoList",
                            new ArrayList<Object>()).toString());
            if (!nevChargeSystemVoltageDtoList.isEmpty()) {
                final HashMap<String, Object> nevChargeSystemVoltageDtoMap = nevChargeSystemVoltageDtoList.get(0);
                GwmDataObj.setCurrentBatteryStartNum(convertIntType("currentBatteryStartNum", nevChargeSystemVoltageDtoMap));
                GwmDataObj.setBatteryVoltage(convertJoinStringType("batteryVoltage", nevChargeSystemVoltageDtoMap));
                GwmDataObj.setChargeSystemVoltage(convertDoubleType("chargeSystemVoltage", nevChargeSystemVoltageDtoMap));
                GwmDataObj.setCurrentBatteryCount(convertIntType("currentBatteryCount", nevChargeSystemVoltageDtoMap));
                GwmDataObj.setBatteryCount(convertIntType("batteryCount", nevChargeSystemVoltageDtoMap));
                GwmDataObj.setChildSystemNum(convertIntType("childSystemNum", nevChargeSystemVoltageDtoMap));
                GwmDataObj.setChargeSystemCurrent(convertDoubleType("chargeSystemCurrent", nevChargeSystemVoltageDtoMap));
            }

            /* ----------------------------------------------driveMotorData-------------------------------------------------- */
            List<HashMap<String, Object>> driveMotorData = jsonToList(vehicleMap.getOrDefault("driveMotorData", new ArrayList()).toString());                                    //驱动电机数据
            if (!driveMotorData.isEmpty()) {
                HashMap<String, Object> driveMotorMap = driveMotorData.get(0);
                GwmDataObj.setControllerInputVoltage(convertDoubleType("controllerInputVoltage", driveMotorMap));
                GwmDataObj.setControllerTemperature(convertDoubleType("controllerTemperature", driveMotorMap));
                GwmDataObj.setRevolutionSpeed(convertDoubleType("revolutionSpeed", driveMotorMap));
                GwmDataObj.setNum(convertIntType("num", driveMotorMap));
                GwmDataObj.setControllerDcBusCurrent(convertDoubleType("controllerDcBusCurrent", driveMotorMap));
                GwmDataObj.setTemperature(convertDoubleType("temperature", driveMotorMap));
                GwmDataObj.setTorque(convertDoubleType("torque", driveMotorMap));
                GwmDataObj.setState(convertIntType("state", driveMotorMap));
            }
            /* -------------------------------------------------------------------------------------------------------------- */

            /* -----------------------------------------nevChargeSystemTemperatureDtoList------------------------------------ */
            List<HashMap<String, Object>> nevChargeSystemTemperatureDtoList = jsonToList(vehicleMap.getOrDefault("nevChargeSystemTemperatureDtoList", new ArrayList()).toString());
            if (!nevChargeSystemTemperatureDtoList.isEmpty()) {
                HashMap<String, Object> nevChargeSystemTemperatureMap = nevChargeSystemTemperatureDtoList.get(0);
                GwmDataObj.setProbeTemperatures(convertJoinStringType("probeTemperatures", nevChargeSystemTemperatureMap));
                GwmDataObj.setChargeTemperatureProbeNum(convertIntType("chargeTemperatureProbeNum", nevChargeSystemTemperatureMap));
            }
            /* -------------------------------------------------------------------------------------------------------------- */

            /* --------------------------------------------ecuErrCodeDataList------------------------------------------------ */
            HashMap<String, Object> xcuerrinfoMap = jsonToHashMap(vehicleMap.getOrDefault("xcuerrinfo", new HashMap<String, Object>()).toString());
            if (!xcuerrinfoMap.isEmpty()) {
                List<HashMap<String, Object>> ecuErrCodeDataList = jsonToList(xcuerrinfoMap.getOrDefault("ecuErrCodeDataList", new ArrayList()).toString());
                if (ecuErrCodeDataList.size() > 4) {
                    GwmDataObj.setVcuFaultCode(convertJoinStringType("errCodes", ecuErrCodeDataList.get(0)));
                    GwmDataObj.setBcuFaultCodes(convertJoinStringType("errCodes", ecuErrCodeDataList.get(1)));
                    GwmDataObj.setDcdcFaultCode(convertJoinStringType("errCodes", ecuErrCodeDataList.get(2)));
                    GwmDataObj.setIpuFaultCodes(convertJoinStringType("errCodes", ecuErrCodeDataList.get(3)));
                    GwmDataObj.setObcFaultCode(convertJoinStringType("errCodes", ecuErrCodeDataList.get(4)));
                }
            }

            //扩展字段，以上已经将json字符串转换为javaBean对象了，为了后续使用方便，在解析类中增加两个扩展属性
            //时间戳、是否异常数据（vin、terminalTime、json解析是否异常）
            if (GwmDataObj.getVin().isEmpty() || GwmDataObj.getTerminalTime().isEmpty()) {
                //异常数据
                GwmDataObj.setErrorData(jsonStr);
            }
            if (!GwmDataObj.getTerminalTime().isEmpty()) {
                //冗余时间戳字段，为了以后作为水印使用的时候指定的事件时间
                GwmDataObj.setTerminalTimeStamp(
                        DateUtils.convertStringToDateTime(GwmDataObj.getTerminalTime(), DateFormatDefine.DATE_TIME_FORMAT).getTime()
                );
            }
        } catch (Exception e) {
            //解析json异常jsonStr="null"
            GwmDataObj.setErrorData(jsonStr);
            logger.error("json数据解析异常，格式错误：" + jsonStr);
        }
        //返回对象
        return GwmDataObj;
    }

    /**
     * 根据指定的key获取到value，并将value值转换成int类型返回
     *
     * @param fieldName
     * @param hashMap
     * @return
     */
    private static int convertIntType(String fieldName, HashMap<String, Object> hashMap) {
        return Integer.parseInt(hashMap.getOrDefault(fieldName, -999999).toString());
    }

    /**
     * 根据指定的key获取到value，并将value值转换成double类型返回
     *
     * @param fieldName
     * @param hashMap
     * @return
     */
    private static double convertDoubleType(String fieldName, HashMap<String, Object> hashMap) {
        return Double.parseDouble(hashMap.getOrDefault(fieldName, -999999D).toString());
    }

    /**
     * 根据指定的key获取到value，并将value值转换成String类型返回
     *
     * @param fieldName
     * @param hashMap
     * @return
     */
    private static String convertStringType(String fieldName, HashMap<String, Object> hashMap) {
        return hashMap.getOrDefault(fieldName, "").toString();
    }

    /**
     * 根据指定的key获取到value，并将value集合列表拼接成String返回
     *
     * @param fieldName
     * @param hashMap
     * @return
     */
    private static String convertJoinStringType(String fieldName, HashMap<String, Object> hashMap) {
        return String.join(",", convertStringToArray(hashMap.getOrDefault(fieldName, new ArrayList<Object>()).toString()));
    }

    /**
     * 将字符串根据，分割，然后转换成集合对象
     *
     * @param str 1,1,2
     * @return
     */
    private static List convertStringToArray(String str) {
        return Arrays.asList(str.split(","));
    }

    /**
     * 将json字符串转换成list集合对象
     *
     * @param jsonStr
     * @return
     */
    private static List<HashMap<String, Object>> jsonToList(String jsonStr) {
        //定义需要返回的集合对象
        List<HashMap<String, Object>> resultList = new ArrayList<>();

        //定义jsonArray对象
        JSONArray jsonArray = new JSONArray(jsonStr);

        //遍历所有的json对象
        for (int i = 0; i < jsonArray.length(); i++) {
            final HashMap<String, Object> hashMap = jsonToHashMap(jsonArray.get(i).toString());
            resultList.add(hashMap);
        }
//        for (Object jsonObject : jsonArray) {
//            final HashMap<String, Object> hashMap = jsonToHashMap(jsonObject.toString());
//            resultList.add(hashMap);
//        }

        //返回集合对象
        return resultList;
    }

    /**
     * 将字符串转换成hashMap对象
     *
     * @param jsonStr
     * @return
     */
    private static HashMap<String, Object> jsonToHashMap(String jsonStr) {
        //定义需要返回的HashMap
        HashMap<String, Object> hashMap = new HashMap<>();

        //定义jsonObject对象
        JSONObject jsonObject = new JSONObject(jsonStr);

        //获取到json所有的key
        final Iterator<String> keys = jsonObject.keys();
        while (keys.hasNext()) {
            final String key = keys.next();
            final Object value = jsonObject.get(key);
            hashMap.put(key, value);
        }

        //返回hashMap对象
        return hashMap;
    }
}
